﻿
// Condition: Write a program that fills and prints a matrix of size (n,n) with particular structure.

using System;



class Matrix_Var2
{
    static void Main()
    {
        // 1.initial statements
        Console.Write("Enter the size of square matrix, n= ");
        int n = int.Parse(Console.ReadLine());
        int count = 1;
        int[,] matrix = new int[n, n];


        // 2. Solution with: one for-loop for column. Check if the column number is odd or even.
        //    Use another loor for row which increase or decrease according column number. 

        for (int col = 0; col < n; col++)
        {
            // solucion for even columns
            if (col % 2 == 0)
            {
                for (int row = 0; row < n; row++)
                {
                    matrix[row, col] = count;
                    count++;
                }
            }
            // solution for odd columns
            else
            {
                for (int row = n-1; row >= 0; row--)
                {
                    matrix[row, col] = count;
                    count++;
                }
            }
        }

        // 3. print the matrix[n,n]

        for (int row = 0; row < n; row++)
        {
            for (int col = 0; col < n; col++)
            {
                Console.Write(matrix[row, col] + " ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();

    }
}

